package com.ym.b2b.provider.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.provider.dao.EmCProviderBelongBuyerDAO;
import com.ym.b2b.provider.sqlbean.EmCProviderBelongBuyer;
import com.zc.commons.base.Page;
import com.zc.commons.dao.ZcDao;

@Repository
public class EmCProviderBelongBuyerDAOImpl<T> extends ZcDao<T> implements EmCProviderBelongBuyerDAO {

    public Long searchPageEmCProviderBelongBuyerNum(EmCProviderBelongBuyer emcproviderbelongbuyer)
                                                                                                  throws DataAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", emcproviderbelongbuyer);
        return (Long) find("EM_C_PROVIDER_BELONG_BUYER.searchPageEmCProviderBelongBuyerNum", map);
    }

    public Page searchPageEmCProviderBelongBuyer(EmCProviderBelongBuyer emcproviderbelongbuyer,
                                                 Page<EmCProviderBelongBuyer> page) throws DataAccessException {
        page.setTotalRow(searchPageEmCProviderBelongBuyerNum(emcproviderbelongbuyer));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("map", emcproviderbelongbuyer);
        map.put("startrow", page.getStartRow());
        map.put("pagesize", page.getPageSize());
        map.put("pageable", page.getPageable());
        page.setRows(list("EM_C_PROVIDER_BELONG_BUYER.searchPageEmCProviderBelongBuyer", map));
        return page;
    }

    public void insertEmCProviderBelongBuyer(EmCProviderBelongBuyer record) throws DataAccessException {
        insert("EM_C_PROVIDER_BELONG_BUYER.insertEmCProviderBelongBuyer", record);
    }

    public int updateEmCProviderBelongBuyer(EmCProviderBelongBuyer record) throws DataAccessException {
        int rows = update("EM_C_PROVIDER_BELONG_BUYER.updateEmCProviderBelongBuyer", record);
        return rows;
    }

    public EmCProviderBelongBuyer searchEmCProviderBelongBuyer(Long belongId) throws DataAccessException {
        EmCProviderBelongBuyer key = new EmCProviderBelongBuyer();
        key.setBelongId(belongId);
        EmCProviderBelongBuyer record = (EmCProviderBelongBuyer) find("EM_C_PROVIDER_BELONG_BUYER.selectEmCProviderBelongBuyer",
                                                                      key);
        return record;
    }

    @Override
    public void deleteEmCProviderBelongBuyer(EmCProviderBelongBuyer emCProviderBelongBuyer) throws DataAccessException {
        delete("EM_C_PROVIDER_BELONG_BUYER.deleteEmCProviderBelongBuyer", emCProviderBelongBuyer);
    }

    @Override
    public void deleteMultipleEmCProviderBelongBuyers(String belongIdList) {
        delete("EM_C_PROVIDER_BELONG_BUYER.deleteMultipleEmCProviderBelongBuyers", belongIdList);
    }
}
